package android.example.graphictest.alphapng;

import java.util.Timer;
import java.util.TimerTask;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;


public class DrawPNGActivity extends Activity
{
	DrawBitmap mDrawBitmap;
	Timer timer;
	TimerTask task = new TimerTask()
	{
		public void run()
		{
			Message msg = new Message();
			msg.what = 0;
			mHandler.sendMessage(msg);
			
		}
	};
	TimerTask task1 = new TimerTask()
	{
		public void run()
		{
			Message msg = new Message();
			msg.what = 1;
			mHandler.sendMessage(msg);
			
		}
	};

	Handler mHandler = new Handler()
	{
		public void handleMessage(Message msg)
		{
		  switch(msg.what)
		  {
		    case 0:
		    	{
		    		setTitle("DrawBitmap FPS = "+String.valueOf(DrawBitmap.fps)+"fps"+"   "
		    	
    				+"count = " + DrawBitmap.count);
		    		
    			}break;
            case 1:
		        {
		    	    if(DrawBitmap.count == 7)
		    	    {
		    	    	task.cancel();
		        	    DrawPNGActivity.this.finish();
		    	    }

		        }break;
		  }
		  
		  super.handleMessage(msg);
		  
		}
	};
	
	@Override
	public void onCreate(Bundle saveInstanceState) 
	{
		super.onCreate(saveInstanceState);
		
		mDrawBitmap = new DrawBitmap(this);
		setContentView(mDrawBitmap);
		
		timer = new Timer();
		timer.schedule(task, 1000,1000);
		timer.schedule(task1, 1000,1000);

	}
	@Override
	public void onDestroy()
	{
		super.onDestroy();
		timer.cancel();
	}
	
}
